#pragma once

#include "comm/my_spin_lock.h"
#include "comm/my_rbtree.h"
#include "comm/my_queue.h"

typedef struct my_disk_hotspot_s my_disk_hotspot_t;

struct my_disk_hotspot_s {
    my_spin_lock_t      lock;
    int64_t             max_item;
    int64_t             max_bytes;

    int                 nlists;
    my_queue_t          *lists;
    int64_t             *lists_bytes;
    int64_t             *lists_n;

    my_rbtree_t         tree;
    my_rbtree_node_t    sentinel;
};

typedef struct {
    uint32_t    digest32;
    int64_t     offset;
    int64_t     size;
} my_disk_hotspot_record_t;

void
my_disk_hotspot_increase_priority(my_disk_hotspot_t *hotspot,
    const my_disk_hotspot_record_t * record);

my_bool_t
my_disk_hotspot_first_cover(my_disk_hotspot_t *hotspot,
    int64_t window_off, int64_t window_size, my_disk_hotspot_record_t *record);

void
my_disk_hotspot_open(my_disk_hotspot_t *hotspot, int nlist, int64_t max_item,
    int64_t max_bytes);

void
my_disk_hotspot_close(my_disk_hotspot_t *hotspot);